
import CryptoJS from "crypto-js";
const getKey = () => CryptoJS.enc.Hex.parse(localStorage.getItem("pubKey"))

/**
 * @description 加密
 * @param word 
 * @returns 
 */
export const Encrypt = (word: string) => {
  const srcs = CryptoJS.enc.Utf8.parse(word);
  const encrypted = CryptoJS.AES.encrypt(srcs, getKey(), {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  const result = encrypted.toString();
  return result;
}

/**
 * @description 解密
 * @param word 
 * @returns 
 */
export const Decrypt = (word: string) => {
  const decrypt = CryptoJS.AES.decrypt(word, getKey(), {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}